#pragma  once
#include "MMemory.h"
BEGIN_MARIONETTE
#define MemorySize 20000
class TestMemory:public MMemory{
public:
	TestMemory(){
		m_writePos = 0;
	}
	template<typename ObjectType>
	DWORD Push(ObjectType* pData){
		int dataSize = sizeof(ObjectType);

		return Push(pData,dataSize);
	}
	DWORD Push(void* pData,int size)
	{
		if(size>MemorySize-m_writePos)
			return -1;
		int pos = m_writePos;
		for(int i=0;i<size;i++)
		{
			m_data[m_writePos++] = ((BYTE*)pData)[i];
		}
		return pos;
	}
	template<typename ObjectType>
	ObjectType* NewObject(){
		int size = sizeof(ObjectType);
		int r = m_writePos;
		if(Skip(size) == true)
			return (ObjectType*)r;
		return NULL;
	}
	bool Seek(int pos){
		if(pos >=0 && pos<MemorySize)
		{
			m_writePos = pos;
			return true;
		}
		return false;

	}
	bool Skip(int skipSize){
		if(skipSize>MemorySize-m_writePos)
			return false;
		m_writePos+=skipSize;
		return true;
	}
	void Reset(){m_writePos = 0;}
protected:
	virtual BYTE Data(DWORD address)
	{
		return m_data[address];
	}
	virtual BYTE* DataPtr(DWORD address)
	{
		return m_data+address;
	}
	BYTE m_data[MemorySize];
	int m_writePos;
};
END_MARIONETTE